package com.ych.modules.cms.authorInfc.user.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ych.modules.base.dbEntity.TUserItemEntity;
import com.ych.modules.common.entity.query.QueryUserItemEntity;
import com.ych.modules.common.service.UserItemService;
import com.ych.utils.mysqlPageUtil.PageUtils;
import com.ych.utils.serviceReturn.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Author: Usopp.tsui
 * Date: 2021/1/2
 * Time: 11:19
 * Description:
 */
@RestController("cmsUserItemController")
@RequestMapping("/cms/auth/user/item")
@Api(tags = {"CMS——用户项目相关"}, description = "CMS——用户项目相关", position = 2)
public class UserItemController {
    @Autowired
    private UserItemService userItemService;

    @PostMapping("/getUserItem")
    @ApiOperation(value = "项目查询", notes = "项目查询")
    public R<TUserItemEntity> getUserItem(@RequestBody String itemId) {
        try {
            TUserItemEntity itemEntity = userItemService.getUserItem(itemId);
            return new R(0, "成功", itemEntity);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/listUserItem")
    @ApiOperation(value = "项目列表查询", notes = "项目列表查询")
    public R<Page<TUserItemEntity>> listUserItem(@RequestBody QueryUserItemEntity entity) {
        try {
            Page<TUserItemEntity> page = userItemService.listUserItem(entity);
            return new R(0, "成功", new PageUtils(page));
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/negation")
    @ApiOperation(value = "启用/禁用", notes = "启用/禁用")
    public R<String> negation(@RequestBody String itemId) {
        try {
            userItemService.negation(itemId);
            return new R(0, "成功", null);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }
}
